<?php

$order_id = 0;

$id=$_GET['id'];
if(!empty($id) && $id>0){
	$order_id = $id;		
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>save_item</title>

<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.2.custom.css" />
<link rel="stylesheet" type="text/css" href="css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/fancybox.css" />

<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="js/jquery.fancybox.js" type="text/javascript"></script>
<script src="js/jquery.message.js" type="text/javascript"></script>

</head>

<body bgcolor="yellow">

<div id="main">
<!--
<h2 class="top_title"><a href="#">常用物品</a></h2>
-->
<div class="grid_table">

     <div id="opt">
        <div id="query">            
            <label>物品名称：</label><input type="text" class="input" id="item_name" />
            <input type="submit" class="btn" id="find_btn" value="查 询" />
        </div>
        <input type="button" class="btn" id="add_btn" value="新 增" />
        <input type="button" class="btn" id="del_btn" value="删 除" />
     </div>

     <table id="list1"></table>
     <div id="pager1"></div>
</div>

<!-- ----------------------- -->

	<div id="opt" align="center"> 
		<input type="button" class="btn" id="ok_btn" value="提 交" />  &nbsp; &nbsp;
		<input type="button" class="btn" id="cancle_btn" value="返回" /> 
	</div>
&nbsp;
</div>

<div id="footer">
    &nbsp;
</div>

<script type="text/javascript">
$("#list1").jqGrid({
	url:'order_do_item.php?action=list',  //请求数据的url地址
	datatype: "json",  //请求的数据类型
   	colNames:['编号','物品名称','数量','单位净重(公斤)','原产地','单价(欧元)','总价(欧元)','总重(公斤)' ], //数据列名称（数组）
   	colModel:[ //数据列各参数信息设置
   		{name:'id',index:'id', editable:true, width:20,align:'center', title:false},
   		{name:'item_name',index:'item_name', width:60, title:false},
		{name:'item_amount',index:'item_amount', width:40},
		{name:'item_pre_weight',index:'item_pre_weight', width:40},
   		{name:'item_madein',index:'item_madein', width:40},   		
		{name:'item_pre_price',index:'item_pre_price', width:40},
		{name:'item_price',index:'item_price', width:40},
		{name:'item_weight',index:'item_weight', width:40}	
   	],
   	rowNum: 10, //每页显示记录数
   	rowList:[10,20,50,100,500], //分页选项，可以下拉选择每页显示记录数
   	pager: '#pager1',  //表格数据关联的分页条，html元素
	autowidth: true, //自动匹配宽度
	height: 290,   //设置高度
	gridview:true, //加速显示
    viewrecords: true,  //显示总记录数
	multiselect: true,  //可多选，出现多选框
	multiselectWidth: 25, //设置多选列宽度
	sortable:true,  //可以排序
	sortname: 'id',  //排序字段名
    sortorder: "desc", //排序方式：倒序，本例中设置默认按id倒序排序
	loadComplete:function(data){ //完成服务器请求后，回调函数
		if(data.records==0){ //如果没有记录返回，追加提示信息，删除按钮不可用
			$("p").appendTo($("#list1")).addClass("nodata").html('找不到相关数据！');
			$("#del_btn1").attr("disabled",true);
		}else{ //否则，删除提示，删除按钮可用
			$("p.nodata").remove();
			$("#del_btn1").removeAttr("disabled");
		}
	}
 });
 

 
 
 
$(function(){

	$("#ok_btn").click(function(){
		var sels = $("#list1").jqGrid('getGridParam','selarrrow');
		//alert("物品="+sels +"  length="+sels.length); //test!		
	    if(sels==""){
		   alert('请选择物品，最多选3个！')
	    }else{
			if(sels.length>3){
				alert('选择多于3个，请选择1-3个！');				
			}else{
				if(confirm("确认选择物品: "+sels+"？")){
					sel1 = sels[0];
					
					sel2 = 0;
					if(sels.length>1){
						sel2 = sels[1];
					}
					
					sel3 = 0;
					if(sels.length>2){
						sel3 = sels[2];
					}
					
					self.location="order_item.php?id=<?php echo $order_id; ?>&s1="+sel1+"&s2="+sel2+"&s3="+sel3;
				}
			}
		
		  
	    }
	});
	
	
	$("#cancle_btn").click(function(){
		//window.history.back(-1); 
		self.location='order_item.php?id=<?php echo $order_id; ?>';
	});
	
	//------------------------------------------------
	
	$("#add_btn").click(function(){
		/*$.fancybox({
			'type':'ajax',
			'href':'order_add_1.php'
		});*/
		self.location='order_address.php';
	});
	
	$("#del_btn").click(function(){
		var sels = $("#list").jqGrid('getGridParam','selarrrow');
	    if(sels==""){
		   alert('请选择要删除的项！')
	    }else{
		   if(confirm("确认删除订单: "+sels+"？")){
		    $.ajax({
              type: "POST",
              url: "order_do.php?action=del",
			  data: "ids="+sels,
			  beforeSend: function() {
                   $().message("正在请求...");
              },
			  error:function(){
				   $().message("请求失败...");
			  },
              success: function(msg){
				   if(msg!=0){
					   var arr = msg.split(',');
					   $.each(arr,function(i,n){
							 if(arr[i]!=""){
								 $("#list").jqGrid('delRowData',n); 
							 }
		               });
		               $().message("已成功删除!");
				   }else{
					   $().message("操作失败！");
				   }
              }
            });
	       }
	    }
	});
	
	$("#find_btn").click(function(){
		var package_name = escape($("#package_name").val()); //对字符串进行编码
	    var order_id = escape($("#order_id").val());       //对字符串进行编码
	    $("#list").jqGrid('setGridParam',{
			url:"order_do.php?action=list",
			postData:{'package_name':package_name,'order_id':order_id},
			page:1
		}).trigger("reloadGrid");
	});
});
</script>

</body>
</html>
